Completed
Push — master ( f15d30...b9cea7 )
by Simon
28s
created

middlewareTest.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 22
rs 9.2

3 Functions

Rating   Name   Duplication   Size   Complexity  
A middlewareTest.js ➔ ... ➔ register.textCommand(ꞌblockꞌ) 0 3 1
A middlewareTest.js ➔ ... ➔ register.textCommand(ꞌexceptionꞌ) 0 3 1
A middlewareTest.js ➔ ... ➔ register.textCommand(ꞌhelpꞌ) 0 11 1
1
const middlware = require('../lib/structure/AbstractMiddleware')
2
class coreCommands extends middlware {
3
  setUp (client, next) {
4
    this.client = client
5
    var register = client.createRegister('core', 'core')
6
    register.textCommand('help', null, function (req, res) {
7
      var message = 'This command was instantied inside a middleware\n'
8
      client.registers.forEach(function (register) {
9
        message += '__' + register.name + '__:\n'
10
        register.forEach(function (command) {
11
          message += '`' + command.name + '` '
12
        })
13
        message += '\n'
14
      })
15
      res.send(message)
16
    })
17
    register.textCommand('block', null, function (req, res) {
0 ignored issues
show
Unused Code introduced by
The parameter res is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter req is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
18
            // this will be blocked
19
    })
20
    register.textCommand('exception', null, function (req, res) {
0 ignored issues
show
Unused Code introduced by
The parameter res is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter req is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
21
            // this will be blocked
22
    })
23
    next()
24
  }
25
  handle (req, res, next) {
26
    console.log('handle')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
27
    if (req.isCommand && req.command.name === 'block') {
28
      res.send('Blocking the middleware chain')
29
      next(true)
30
    }
31
    if (req.isCommand && req.command.name === 'exception') {
32
      res.send('Creating an exception')
33
      next(new Error('Exception'))
34
    }
35
    req.test = true
36
    next(null, req, res)
37
  }
38
}
39
module.exports = coreCommands
40